added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBAutomateWord / MainModule.vb
blob0ab0cf3682f3bfbcd700ec645d23b8eac7972015
1 '****************************** Module Header ******************************'
2 ' Module Name: MainModule.vb
3 ' Project: VBAutomateWord
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' The VBAutomateWord example demonstrates the use of Visual Basic.NET codes
7 ' to create a Microsoft Word instance, create a new document, insert a
8 ' paragraph and a table, save the document, close the Microsoft Word
9 ' application and then clean up unmanaged COM resources.
11 ' Office automation is based on Component Object Model (COM). When you call a
12 ' COM object of Office from managed code, a Runtime Callable Wrapper (RCW) is
13 ' automatically created. The RCW marshals calls between the .NET application
14 ' and the COM object. The RCW keeps a reference count on the COM object. If
15 ' all references have not been released on the RCW, the COM object of Office
16 ' does not quit and may cause the Office application not to quit after your
17 ' automation. In order to make sure that the Office application quits cleanly,
18 ' the sample demonstrates two solutions.
20 ' Solution1.AutomateWord demonstrates automating Microsoft Word application by
21 ' using Microsoft Word Primary Interop Assembly (PIA) and explicitly assigning
22 ' each COM accessor object to a new varaible that you would explicitly call
23 ' Marshal.FinalReleaseComObject to release it at the end.
25 ' Solution2.AutomateWord demonstrates automating Microsoft Word application by
26 ' using Microsoft Word PIA and forcing a garbage collection as soon as the
27 ' automation function is off the stack (at which point the RCW objects are no
28 ' longer rooted) to clean up RCWs and release COM objects.
30 ' This source is subject to the Microsoft Public License.
31 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
32 ' All other rights reserved.
34 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
35 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
36 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
37 '***************************************************************************'
40 Module MainModule
42 <STAThread()> _
43 Sub Main()
45 ' Solution1.AutomateWord demonstrates automating Microsoft Word
46 ' application by using Microsoft Word PIA and explicitly assigning
47 ' each COM accessor object to a new varaible that you would
48 ' explicitly call Marshal.FinalReleaseComObject to release it at the
49 ' end.
50 Solution1.AutomateWord()
52 Console.WriteLine()
54 ' Solution2.AutomateWord demonstrates automating Microsoft Word
55 ' application by using Microsoft Word PIA and forcing a garbage
56 ' collection as soon as the automation function is off the stack (at
57 ' which point the RCW objects are no longer rooted) to clean up RCWs
58 ' and release COM objects.
59 Solution2.AutomateWord()
61 End Sub
63 End Module